package cn.tansanqinger.dao.sql.usernumber;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.tansanqinger.dao.sql.IDayNumberSqlDao;
import cn.tansanqinger.dao.sql.IMonthNumberSqlDao;
import cn.tansanqinger.dao.sql.IYearNumberSqlDao;
import cn.tansanqinger.pojo.Daynumber;
import cn.tansanqinger.pojo.Monthnumber;
import cn.tansanqinger.pojo.Yearnumber;

@Repository
public class UserNumberSqlDaoImpl {
	
	@Autowired
	private IDayNumberSqlDao ddao;
	@Autowired
	private IMonthNumberSqlDao mdao;
	@Autowired
	private IYearNumberSqlDao ydao;
	
	/**
	 * 当前年的教师申请数据
	 * @param year
	 * @return
	 */
	public int thisYearTeacher(String year) {
		QueryWrapper<Yearnumber> queryWrapper = new QueryWrapper<Yearnumber>();
		queryWrapper.lambda().eq(Yearnumber::getJurisdiction, 1).eq(Yearnumber::getYear, year);
		Yearnumber yearnumber = ydao.selectOne(queryWrapper);
		return yearnumber==null? 0 : yearnumber.getNumber();
	}
	
	/**
	 * 当前年的学生申请数据
	 * @param year
	 * @return
	 */
	public int thisYearStudent(String year) {
		QueryWrapper<Yearnumber> queryWrapper = new QueryWrapper<Yearnumber>();
		queryWrapper.lambda().eq(Yearnumber::getJurisdiction, 0).eq(Yearnumber::getYear, year);
		Yearnumber yearnumber = ydao.selectOne(queryWrapper);
		return yearnumber==null? 0 : yearnumber.getNumber();
	}
	
	/**
	 * 当前年的全部申请数据
	 * @param year
	 * @return
	 */
	public int thisYearAll(String year) {
		return thisYearStudent(year)+thisYearTeacher(year);
	}
	
	/**
	 * 当前月的教师申请数据
	 * @param year
	 * @return
	 */
	public int thisMonthTeacher(String month) {
		QueryWrapper<Monthnumber> queryWrapper = new QueryWrapper<Monthnumber>();
		queryWrapper.lambda().eq(Monthnumber::getJurisdiction, 1).eq(Monthnumber::getMonth, month);
		Monthnumber monthnumber = mdao.selectOne(queryWrapper);
		return monthnumber==null? 0 : monthnumber.getNumber();
	}
	
	/**
	 * 当前月的学生申请数据
	 * @param year
	 * @return
	 */
	public int thisMonthStudent(String month) {
		QueryWrapper<Monthnumber> queryWrapper = new QueryWrapper<Monthnumber>();
		queryWrapper.lambda().eq(Monthnumber::getJurisdiction, 0).eq(Monthnumber::getMonth, month);
		Monthnumber monthnumber = mdao.selectOne(queryWrapper);
		return monthnumber==null? 0 : monthnumber.getNumber();
	}
	
	/**
	 * 当前月的全部申请数据
	 * @param year
	 * @return
	 */
	public int thisMonthAll(String month) {
		return thisMonthStudent(month)+thisMonthTeacher(month);
	}
	
	/**
	 * 当前日期的教师申请数据
	 * @param year
	 * @return
	 */
	public int thisDayTeacher(String day) {
		QueryWrapper<Daynumber> queryWrapper = new QueryWrapper<Daynumber>();
		queryWrapper.lambda().eq(Daynumber::getJurisdiction, 1).eq(Daynumber::getDay, day);
		Daynumber daynumber = ddao.selectOne(queryWrapper);
		return daynumber==null? 0 : daynumber.getNumber();
	}
	
	/**
	 * 当前日期的学生申请数据
	 * @param year
	 * @return
	 */
	public int thisDayStudent(String day) {
		QueryWrapper<Daynumber> queryWrapper = new QueryWrapper<Daynumber>();
		queryWrapper.lambda().eq(Daynumber::getJurisdiction, 0).eq(Daynumber::getDay, day);
		Daynumber daynumber = ddao.selectOne(queryWrapper);
		return daynumber==null? 0 : daynumber.getNumber();
	}
	
	/**
	 * 当前日期的全部申请数据
	 * @param year
	 * @return
	 */
	public int thisDayAll(String day) {
		return thisDayStudent(day)+thisDayTeacher(day);
	}

}
